package com.fileshare.web.handler;

import com.fileshare.web.exception.TipException;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * View 统一异常处理
 */
@ControllerAdvice(annotations = Controller.class)
public class GlobalViewExceptionHandler {

    @ExceptionHandler(value = AccessDeniedException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public String accessException(Exception e) {
        e.printStackTrace();
        return "comm/error_403";
    }

    @ExceptionHandler(value = TipException.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String tipException(Exception e) {
        e.printStackTrace();
        return "comm/error_500";
    }


    @ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    public String exception(Exception e) {
        e.printStackTrace();
        return "comm/error_404";
    }
}
